//
//  DataManager.h
//  iFlickr
//
//  Created by 张 霄鹤 on 09-5-31.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//


#import <Foundation/Foundation.h>
#import "XMLRPCResponse.h"

#import "FlickrParser.h"

#import "PhotosetInfo.h"

@interface DataManager : NSObject {
	NSString *userId;
	
	NSString *userName;
	
	NSString *userFullName;
	
	NSString *perms;
	
	/**
	 * API_KEY  32fdd35bca5b784340c0bdf523b9d3cc 
	 */
	NSString *apiKey;
	
	/**
	 * secret key fe8a457a3077648b
	 */
	NSString *secretKey;
	/**
	 * Frob
	 */
	NSString *frob;
	
	NSString *token;
	
	NSString *desc;
	
	FlickrParser *fparser;
}

@property(nonatomic, retain) NSString *token;

@property(nonatomic, retain) NSString *perms;

@property(nonatomic, retain) NSString *userId;

@property(nonatomic, retain) NSString *userName;

@property(nonatomic, retain) NSString *userFullName;

+(id) sharedDataManager;

+(id) alloc;

-(id)initWithApikeyAndSecret:(NSString *)api_key secret:(NSString *)key;

-(NSURL *) getFrobAndAuthURL;

/**
 * 计算 api_sig 同时，会检查 是否添加了 api_key ，如果没有则添加
 */
-(NSString *)genApiSign:(NSString *)method params:(NSDictionary *)paramDict;

-(NSString *)getFrobFromServer;

-(NSString *)getUserToken;

-(BOOL)saveAuthInfo:(NSDictionary *)info;

-(BOOL)loadAuthInfo;

-(BOOL)isAuthorized;

-(void)logout;

#pragma mark -
#pragma mark AppDocumentPath
/**
 Returns the path to the application's documents directory.
 */
- (NSString *)applicationDocumentsDirectory ;


#pragma mark uploadPhoto
/**
 * 上传图像到服务器，返回 photoid 或者是 错误信息
 * @param data 图像二进制数据
 * @param params 图像描述信息
 * @return id photoid 或者是错误信息
 */
-(id)uploadImageToServer:(NSData *)data withParams:(NSDictionary *)params;

-(NSData *)convertMultipart:(NSDictionary *)params withDesc:(NSString *)de;

#pragma mark -
#pragma mark SharePhotos

/**
 * 通过用户ID，以及图像ID来获取图像地址
 */
-(NSString *) getPhotoURL:(NSString *)nsid withID:(NSString *)photoid;

#pragma mark -
#pragma mark Photoset

/**
 * 获取指定用户的照片集
 * 返回结果中 保存的是 PhotosetInfo 类型
 */
-(NSArray *) getPhotosetsByID:(NSString *)nsid;

/**
 * 将photoID 添加到 照片集中
 */
-(BOOL)addPhotoToSet:(NSString *)photoID toSet:(NSString *)setID;

/**
 * 通过参数进行照片集的创建
 * @param params 照片集的描述信息，其中必须包括 title, primary_photo_id , 可以包括 description
 * @return id 如果成功返回 PhotosetInfo, 如果失败返回 NSError
 */
-(PhotosetInfo *) createPhotoset:(NSDictionary *)params;

@end
